<?php

namespace app\Modules\Api\controllers;

use Yii;
use yii\web\Controller;
use app\filters\Json;
/**
 * Default controller for the `Api` module
 */
class ControllerBase extends Controller
{
    public $enableCsrfValidation = false;

    public function behaviors()
    {
        return [
            [
                'class' => \yii\filters\Cors::className(),
                'cors' => [
                    'Origin'=>['*'],
                    // restrict access to
                    'Access-Control-Request-Method' => ['*'],
                    // Allow only POST and PUT methods
                    'Access-Control-Request-Headers' => ['*'],
                    // Allow only headers 'X-Wsse'
                    'Access-Control-Allow-Credentials' => true,
                    // Allow OPTIONS caching
                    'Access-Control-Max-Age' => 3600,
                    // Allow the X-Pagination-Current-Page header to be exposed to the browser.
                    'Access-Control-Expose-Headers' => ['X-Pagination-Current-Page'],
                ],
            ],
            [
                'class' => Json::className(),
            ],
        ];
    }

    /**
     * 保留html
     */
    protected function html()
    {
        $response = Yii::$app->response;
        $response->format = \yii\web\Response::FORMAT_HTML;
        $this->layout = false;
    }
}